package com.tim.spring;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

import com.tim.spring.bean.ClassInfo;
import com.tim.spring.bean.UserInfo;

public class Test {
	private UserInfo userInfo;
	private ClassInfo classInfo;

	public Test(UserInfo userInfo, ClassInfo classInfo) {
		this.userInfo = userInfo;
		this.classInfo = classInfo;
	}

	public void display() {
		System.out.println("用户信息如下：");
		System.out.println("用户编号: " + userInfo.getUserId());
		System.out.println("用户名称：" + userInfo.getUserName());
		System.out.println("密码：" + userInfo.getUserPwd());
		System.out.println("==============================================");
		System.out.println("班级信息如下：");
		System.out.println("班级编号：" + classInfo.getClassId());
		System.out.println("班级名称：" + classInfo.getClassName());
		System.out.println("班级描述：" + classInfo.getClassDesc());
	}

	public static void main(String[] args) {
		Resource resource = new FileSystemResource("src/com/tim/spring/applicationContext.xml");
		BeanFactory factory = new XmlBeanFactory(resource);
		Test test = (Test) factory.getBean("test");
		test.display();

		System.out.println();
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"applicationContext.xml", Test.class);
		test = (Test) context.getBean("test");
		test.display();
	}
}
